#include "Bezier.h"
#define N 3
int Bezier::func(int n)
{
	if (n == 0 || n == 1) {
		return 1;
	}
	else {
		return n * func(n - 1);
	}
}

double Bezier::Bernstein(double t, int i)
{
	return (func(N) * pow(t, i) * pow((1 - t), (N - i))) / (func(i) * func(N - i));
}

void Bezier::Draw(E_Point* P,int Start,int End)
{
	setlinecolor(BLACK);
	moveto(P[Start].x, P[Start].y);
	for (double t = 0; t < 1; t += 0.0001) {
		double x = 0, y = 0;
		for (int i = 0; i <= N; i++) {
			x += Bernstein(t, i) * P[Start + i].x;
			y += Bernstein(t, i) * P[Start + i].y;
		}
		lineto(x, y);
	}
}
